﻿// Decompiled with JetBrains decompiler
// Type: MCM.Abstractions.Base.BaseSettings
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using HarmonyLib.BUTR.Extensions;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

#nullable enable
namespace MCM.Abstractions.Base
{
  public abstract class BaseSettings : INotifyPropertyChanged
  {
    private static readonly ConcurrentDictionary<Type, BaseSettings.SettingsCtor> _cachedConstructors = new ConcurrentDictionary<Type, BaseSettings.SettingsCtor>();
    public const string SaveTriggered = "SAVE_TRIGGERED";
    public const string LoadingComplete = "LOADING_COMPLETE";
    public const string DefaultPresetId = "default";
    public const string DefaultPresetName = "{=BaseSettings_Default}Default";

    public virtual event PropertyChangedEventHandler? PropertyChanged;

    public abstract string Id { get; }

    public abstract string DisplayName { get; }

    public virtual string FolderName { get; } = string.Empty;

    public virtual string SubFolder => string.Empty;

    public virtual string FormatType => "none";

    public virtual string DiscoveryType => "none";

    public virtual int UIVersion => 1;

    public virtual char SubGroupDelimiter => '/';

    public virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
    {
      PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
      if (propertyChanged == null)
        return;
      propertyChanged((object) this, new PropertyChangedEventArgs(propertyName));
    }

    public virtual BaseSettings CreateNew()
    {
      Type type = this.GetType();
      return BaseSettings._cachedConstructors.GetOrAdd(type, (Func<Type, BaseSettings.SettingsCtor>) (t => AccessTools2.GetConstructorDelegate<BaseSettings.SettingsCtor>(t) ?? (BaseSettings.SettingsCtor) (() => (BaseSettings) FormatterServices.GetUninitializedObject(t))))();
    }

    public virtual BaseSettings CopyAsNew()
    {
      BaseSettings settings = this.CreateNew();
      SettingsUtils.OverrideSettings(settings, this);
      return settings;
    }

    public virtual IEnumerable<ISettingsPreset> GetBuiltInPresets()
    {
      yield return (ISettingsPreset) new MemorySettingsPreset(this.Id, "default", "{=BaseSettings_Default}Default", new Func<BaseSettings>(this.CreateNew));
    }

    private delegate BaseSettings SettingsCtor();
  }
}
